package com.fy.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fy.entity.Insurancev;
import com.fy.entity.Result;
import com.fy.entity.Search;
import com.fy.service.IInsurancevService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author 晓岩
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/ins")
public class InsurancevController {
    @Autowired
    IInsurancevService insurancevService;

    @RequestMapping("list")
    public Result list(@RequestBody Search search){
        QueryWrapper<Insurancev> queryWrapper = new QueryWrapper<>();
        if(search.getTname()!=null && !search.getTname().equals("")){
            queryWrapper.like("tname",search.getTname());
        }
        if(search.getSname()!=null && !search.getSname().equals("")){
            queryWrapper.like("sname",search.getSname());
        }
        if(search.getBname()!=null && !search.getBname().equals("")){
            queryWrapper.like("bname",search.getBname());
        }
        if(search.getType()!=null && !search.getType().equals("")){
            queryWrapper.eq("type",search.getType());
        }
        if(search.getXprice1()!=null){
            queryWrapper.ge("xprice",search.getXprice1());
        }
        if(search.getXprice2()!=null){
            queryWrapper.le("xprice",search.getXprice2());
        }
        Page<Insurancev> page = new Page<>(search.getPage(),search.getPageSize());
        Page<Insurancev> page1 = insurancevService.page(page);
        return new Result(200,"",page1);
    }
    @RequestMapping("del")
    public Result del(String ids){
        System.out.println(ids+"44444444444444444444444");
        String[] split = ids.split(",");
        System.out.println(split+"3333333333333333333333333");
        boolean b = insurancevService.removeById(split);
        if(b){
            return new Result(200,"","删除成功");
        }else{
            return new Result(201,"","删除失败");
        }
    }
}
